package com.example.service.impl;

import com.example.mapper.DepartmentMapper;
import com.example.pojo.Department;
import com.example.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * @program: personnel-management
 * @description: 部门服务层接口
 * @author: ChenZhiXiang
 * @create: 2019-07-16 16:14
 **/
@Service
@Transactional
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    /**
     * 增加部门
     * @param department
     * @return
     */
    @Override
    public int addDep(Department department) {
        department.setEnabled(true);
        departmentMapper.addDep(department);
        return department.getResult();
    }

    /**
     * 删除部门
     * @param did
     * @return
     */
    @Override
    public int deleteDep(Long did) {
        Department department = new Department();
        department.setId(did);
        departmentMapper.deleteDep(department);
        return department.getResult();
    }

    /**
     * 根据父部门ID查询部门
     * @param pid
     * @return
     */
    @Override
    public List<Department> getDepByPid(Long pid) {
        return departmentMapper.getDepByPid(pid);
    }

    /**
     *
     * @return
     */
    @Override
    public List<Department> getAllDeps() {
        return departmentMapper.getAllDeps();
    }
}
